草庐IT

PHPUnit 模拟 View 助手 ZF2

全部标签

ruby - 如何从 Ruby 中的 Mocha 模拟返回动态值

我的问题的要点如下:-我正在用Ruby为下面表示为“post_to_embassy”的方法编写一个Mocha模拟。出于描述问题的目的,实际方法的作用并不是我们真正关心的。但我需要模拟返回一个动态值。下面的proc'&prc'代替实际方法正确执行。但是Mocha中的“with”方法只允许返回bool值。所以下面的代码输出nil。我需要它来输出通过orderInfoXml传递的值。有人知道我可以使用的替代方法吗?require'rubygems'require'mocha'includeMocha::APIclassEmbassyInterfacedefpost_to_embassy(xm

ruby-on-rails - RSpec - 模拟类方法

我正在尝试用rspec模拟一个类方法:lib/db.rbclassDbdefself.list(options)Db::Payload.list(options)endendlib/db/payload.rbclassDb::Payloaddefself.list(options={})endend在我的规范中,我正在尝试设置预期Db::Payload.list在我调用Db.list时将被调用:require'db/payload'describeDbdobefore(:each)do@options={}Db::Payload.should_receive(:list).with(@

ruby-on-rails - 在 Ruby on Rails 中查找未使用的 View /部分

我目前正在从事一个大型的RubyonRails项目。它已经足够老,也足够大,以至于不清楚是否所有View都在实际使用中。有没有可以生成未使用View文件列表的脚本/插件? 最佳答案 我写了一个脚本来查找未使用的部分/View。不过,我假设“未使用”意味着存在一个View文件,但没有为其定义Controller方法(不再)。该脚本不检查View是否被调用,因为没有从默认路由到它的链接。这会复杂得多。将以下脚本放在应用程序的脚本文件夹中:#!/usr/bin/envrubyrequire'config/environment'(Dir[

ruby-on-rails - 使用 Rails 助手来呈现部分

据我了解,helpers主要用于从一些特定于View的逻辑中清理View。但是在我目前的新项目(遗留应用程序)中,我偶然发现了很多看起来像这样的助手defitempreparerender:partial=>'items/itemlist_summary'end这是正确的吗?对我来说,呈现部分内容似乎是您想在View中执行的操作,因为它不包含任何需要抽象的逻辑。我应该直接内联所有这些助手吗? 最佳答案 渲染部分不属于助手。帮助者应该帮助你做有逻辑的事情。逻辑不属于Controller,除非它是渲染部分并决定是否应显示某些内容的逻辑。

ruby - Rspec 模拟错误 : wrong number of arguments

我正在尝试使用Rspec对StripeAPI进行stub,但我遇到了一个问题。这是我的代码的样子:Stripe::Customer.should_receive(:create).with(any_args).and_raise(Stripe::CardError)这是我遇到的错误:Failure/Error:Stripe::Customer.should_receive(:create).with(any_args).and_raise(Stripe::CardError)ArgumentError:wrongnumberofarguments(0for3..6)

ruby-on-rails - 模拟 rspec 中的错误/异常(不仅仅是它的类型)

我有一段代码是这样的:defsome_methodbegindo_some_stuffrescueWWW::Mechanize::ResponseCodeError=>eife.response_code.to_i==503handle_the_situationendendend我想测试ife.response_code.to_i==503部分发生了什么。我可以模拟do_some_stuff以抛出正确类型的异常:whatever.should_receive(:do_some_stuff).and_raise(WWW::Mechanize::ResponseCodeError)但是我

ruby - Selenium 滚动元素进入(中心) View

当一个元素在selenium的View之外并且试图与之交互时,selenium通常会首先隐式地将元素滚动到View中。这很棒,只是烦人的是它通常将元素放入View中。我的意思是,如果元素位于窗口下方,它会向下滚动足够多直到元素刚好与窗口边缘接壤。通常这很好,但是当在周围有边框的网站上工作时,这将导致许多此类错误Selenium::WebDriver::Error::UnknownError:unknownerror:Elementisnotclickableatpoint(438,747).Otherelementwouldreceivetheclick:...因为通常网页的边框都在它

ruby-on-rails - 助手设计 : could not find the `Warden::Proxy` instance on request environment

我尝试将Devise用于我的Rails应用程序。我可以注册并登录,但是当我转到其他页面“构建”时,出现以下错误:Devise::MissingWardeninHome#showDevisecouldnotfindtheWarden::Proxyinstanceonyourrequestenvironment.MakesurethatyourapplicationisloadingDeviseandWardenasexpectedandthattheWarden::Managermiddlewareispresentinyourmiddlewarestack.Ifyouareseeing

ruby-on-rails - 保留 ActiveAdmin 布局的 ActiveAdmin 自定义 View

我有一个带有ActiveAdmingem的Rails3应用程序。我的目标是在自定义View中呈现自定义Controller以保持其布局。我成功地使用以下代码在自定义View中制作自定义Controller渲染:页面.rb:ActiveAdmin.register_page'Pages'docontentonly::indexdorender'index'endcontentonly::editdorenderpartial:'edit'endcontrollerdodefindex@search=Page.includes(:translations).where("page_tran

ruby-on-rails - 匿名 Controller 的 Rspec stubing View

我正在尝试在应用程序Controller上测试一种方法,该方法将用作前置过滤器。为此,我在测试中设置了一个匿名Controller,并应用了before过滤器以确保其正常运行。目前的测试是这样的:describeApplicationControllerdocontrollerdobefore_filter:authenticateddefindexendenddescribe"userauthenticated"dolet(:session_id){"session_id"}let(:user){OpenStruct.new(:email=>"pythonandchips@gmail